#include "HelloWorldScene.h"

using namespace cocos2d;

CCScene* HelloWorld::scene()
{
    CCScene *scene = CCScene::create();
    
    HelloWorld *layer = HelloWorld::create();

    scene->addChild(layer);

    return scene;
}

bool HelloWorld::init()
{
    if ( !CCLayerColor::initWithColor(ccc4(255, 255, 255, 255)) )
    {
        return false;
    }

    /////////////////////////////

    CCSize s = CCDirector::sharedDirector()->getWinSize();

    // 스프라이트 생성 및 초기화

	pMan = CCSprite::create("Images/grossini_dance_01.png");
    pMan->setPosition( ccp(s.width / 2, s.height / 2) );
    this->addChild(pMan);

    

    
    CCAnimation *animation = CCAnimation::create();
    animation->setDelayPerUnit(0.3);
    
    animation->addSpriteFrameWithFileName("Images/grossini_dance_01.png");
    animation->addSpriteFrameWithFileName("Images/grossini_dance_02.png");
    animation->addSpriteFrameWithFileName("Images/grossini_dance_03.png");
    animation->addSpriteFrameWithFileName("Images/grossini_dance_04.png");
    animation->addSpriteFrameWithFileName("Images/grossini_dance_05.png");
    animation->addSpriteFrameWithFileName("Images/grossini_dance_06.png");
    animation->addSpriteFrameWithFileName("Images/grossini_dance_07.png");
    animation->addSpriteFrameWithFileName("Images/grossini_dance_08.png");
    animation->addSpriteFrameWithFileName("Images/grossini_dance_09.png");
    animation->addSpriteFrameWithFileName("Images/grossini_dance_10.png");
    animation->addSpriteFrameWithFileName("Images/grossini_dance_11.png");
    animation->addSpriteFrameWithFileName("Images/grossini_dance_12.png");
    animation->addSpriteFrameWithFileName("Images/grossini_dance_13.png");
    animation->addSpriteFrameWithFileName("Images/grossini_dance_14.png");
    
    CCAnimate *animate = CCAnimate::create(animation);

    pMan->runAction(animate);  // 1회 실행

    CCAction* rep = CCRepeatForever::create(animate);
    pMan->runAction(rep);   // 반복 실행
    
    
//    pMan->runAction(CCRepeatForever::create(CCAnimate::create(animation)));

    
    
    
    return true;
}






